home *** CD-ROM | disk | FTP | other *** search
/ PC Open 93 / PC Open 93 CD 2.bin / PDF / webdeveloper / lezione_4 / listato 7.txt < prev    next >
Encoding:
Text File  |  2004-01-07  |  2.7 KB  |  105 lines

  1. LISTATO 7 û INSERISCIFOTO_RISPOSTA_2.ASP
  2.  
  3. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4.  
  5. <html>
  6. <head>
  7.     <title>Gestione foto di Mario Rossi</title>
  8. </head>
  9.  
  10. <body>
  11.  
  12. <h1>Inserimento nuova foto</h1>
  13.  
  14. <%
  15.  
  16. Const adOpenForwardOnly = 0
  17. Const adLockReadOnly = 1
  18.  
  19. Dim contatore
  20. Dim sql1,sql2
  21. Dim conn, rs
  22. Dim i,j
  23.  
  24. Dim strNome, strTitolo, strData, strLuogo, strProvincia, strStato
  25.  
  26. strNome = request.Form("nome")
  27. strTitolo = request.Form("titolo")
  28. strData = request.Form("datagg") & "/" & request.Form("datamm") & "/" & request.Form("datayyyy")
  29. strLuogo = request.Form("luogo")
  30. strProvincia = request.Form("provincia")
  31. strStato = request.Form("stato")
  32.  
  33. Set conn = Server.CreateObject("ADODB.Connection")
  34. conn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & server.MapPath("/mdb-database/foto2.mdb")
  35.  
  36. sql = "SELECT count(*) AS totale FROM Foto WHERE nome = '" & request.Form("nome") & "'"
  37.  
  38. Set rs = Server.CreateObject("ADODB.RecordSet")
  39. rs.Open sql, conn, adOpenForwardOnly, adLockReadOnly
  40.  
  41. 'Qualche controllo
  42.  
  43. If rs("totale") > 0 Then
  44.     'Esiste una foto giα inserita con lo stesso ID
  45.     response.write "Questo nome di foto esiste giα nella tabella, devi sceglierne un altro<br>"
  46.     response.write "Ritorna alla<a href=""inseriscifoto.asp"">pagina di inserimento</a>"
  47.     response.end
  48. End If
  49.  
  50. If Not IsDate(strData) Then
  51.     'Data in formato non valido
  52.     response.write "La data inserita (" & strData & ") non Φ valida<br>"
  53.     response.write "Ritorna alla<a href=""inseriscifoto.asp"">pagina di inserimento</a>"
  54.     response.end
  55. End If
  56.  
  57. 'Rinforzo l'accento per evitare problemi in inserimento
  58. strNome   = replace(strNome,"'","''")
  59. strTitolo = replace(strTitolo,"'","''")
  60. strLuogo = replace(strLuogo,"'","''")
  61.  
  62. sql = "INSERT INTO Foto ( Nome, Titolo, Data, Luogo, IdProvincia, IdStato ) VALUES (" & _
  63.     "'" & strNome & "', " & _
  64.     "'" & strTitolo & "', " & _
  65.     "'" & strData & "', " & _
  66.     "'" & strLuogo & "', " & _
  67.     "'" & strProvincia & "', " & _
  68.     "'" & strStato & "' " & _
  69.     ")"
  70.  
  71. on error resume next
  72.  
  73. conn.Execute sql
  74.  
  75. If ConnError(conn) > 0 Then
  76.     response.write "Si Φ verificato un problema con l'inserimento dei dati.<br>"
  77.     response.write "Ritorna alla <a href=""inseriscifoto.asp"">pagina di inserimento</a>"
  78. Else
  79.     response.write "I dati della foto sono stati inseriti correttamente<br>"
  80.     response.write "Ritorna all'<a href=""gestione.asp"">elenco delle foto</a>"
  81. End If
  82.  
  83. on error goto 0
  84.  
  85. set rs = nothing
  86. conn.close
  87. set conn = nothing
  88.  
  89. Function ConnError(conn)
  90.  
  91.   Dim i
  92.   i = 0
  93.  
  94.   For Each errorObject In conn.Errors
  95.       i = i + 1
  96.     Response.Write "ERRORE: " & errorObject.Description & "<br><br>"
  97.   Next
  98.  
  99.   ConnError = i
  100.  
  101. End Function
  102.  
  103. %>
  104.  
  105.